package cc.magicjson.example.demo.gemini;

import java.util.Random;

public class MontyHallProblemByGemini {

    private static final int NUM_DOORS = 3;
    private static final int NUM_SIMULATIONS = 100000;

    public static void main(String[] args) {
        int winsWithSwitch = 0;
        int winsWithoutSwitch = 0;

        Random random = new Random();

        for (int i = 0; i < NUM_SIMULATIONS; i++) {
            int winningDoor = random.nextInt(NUM_DOORS);
            int chosenDoor = random.nextInt(NUM_DOORS);

            int openedDoor;
            do {
                openedDoor = random.nextInt(NUM_DOORS);
            } while (openedDoor == winningDoor || openedDoor == chosenDoor);

            if (chosenDoor == winningDoor) {
                winsWithoutSwitch++;
            } else {
                winsWithSwitch++;
            }
        }

        double winPercentageWithSwitch = (double) winsWithSwitch / NUM_SIMULATIONS * 100;
        double winPercentageWithoutSwitch = (double) winsWithoutSwitch / NUM_SIMULATIONS * 100;

        System.out.println("Win percentage with switch: " + winPercentageWithSwitch + "%");
        System.out.println("Win percentage without switch: " + winPercentageWithoutSwitch + "%");
    }
}
